<template>
  <div class="new-project">
    <Wrapper class="wrapper">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" class="project-form">
        <el-form-item label="项目名称:" prop="name">
          <el-col :span="12">
            <el-input
              v-model="form.name"
              :maxlength="30"
              show-word-limit
              placeholder="输入内容"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="培训年度:" prop="annual">
          <el-select v-model="form.annual" placeholder="培训年度">
            <el-option label="2021年度" value="2021" />
            <el-option label="2020年度" value="2020" />
          </el-select>
        </el-form-item>
        <el-form-item label="培训日期:" required class="date-wrapper">
          <el-col :span="5">
            <el-form-item prop="dateStart">
              <el-date-picker v-model="form.dateStart" type="date" placeholder="开始日期" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col class="line" :span="1" style="text-align:center">-</el-col>
          <el-col :span="5">
            <el-form-item prop="dateEnd">
              <el-date-picker v-model="form.dateEnd" type="date" placeholder="结束日期" style="width: 100%;" />
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item class="time-wrapper" label="培训时间段:" required>
          <el-col :span="5">
            <el-form-item prop="timeStart">
              <el-time-picker v-model="form.timeStart" placeholder="开始时间" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col class="line" :span="1" style="text-align:center">-</el-col>
          <el-col :span="5">
            <el-form-item prop="timeEnd">
              <el-time-picker v-model="form.timeEnd" placeholder="结束时间" style="width: 100%;" />
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="培训地点:" prop="location">
          <el-col :span="12">
            <el-input
              v-model="form.location"
              :maxlength="30"
              show-word-limit
            />
          </el-col>
        </el-form-item>
        <el-form-item label="学时:" prop="period">
          <el-col :span="4">
            <el-input-number v-model="form.period" :min="1" />
          </el-col>
          <el-col :span="2" class="period-show-wrapper">
            学分: <span class="period-show">{{ form.period }}</span>
          </el-col>
        </el-form-item>
        <el-row>
          <el-col :span="5"><el-form-item label="选择学段:" prop="phase">
            <el-select v-model="form.phase" placeholder="所有学段">
              <el-option label="高中" value="高中" />
              <el-option label="初中" value="初中" />
            </el-select>
          </el-form-item></el-col>
          <el-col :span="5"><el-form-item label="选择学科:" prop="subject">
            <el-select v-model="form.subject" placeholder="所有学科">
              <el-option label="数学" value="数学" />
              <el-option label="语文" value="语文" />
            </el-select>
          </el-form-item></el-col>
          <el-col :span="8">
            <el-form-item label="培训对象:" prop="member">
              <el-select v-model="form.member" class="member-choose" multiple filterable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="项目详情:" prop="details">
          <el-col :span="20">
            <quill-editor ref="details" v-model="form.details" class="ql-editor" />
          </el-col>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('form')">发布</el-button>
          <el-button @click="resetForm('form')">重置</el-button>
        </el-form-item>
      </el-form>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
      <p>测试</p>
    </Wrapper>
  </div>
</template>

<script>
import { quillEditor } from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
export default {
  components: {
    quillEditor
  },
  data() {
    return {
      // 表单数据
      form: {
        name: '',
        date: '',
        time: '',
        phase: '',
        member: '',
        period: '',
        annual: '',
        timeEnd: '',
        dateEnd: '',
        subject: '',
        details: '',
        location: '',
        dateStart: '',
        timeStart: ''
      },
      // 表单效验
      rules: {
        name: [
          { required: true, message: '请输入项目名称', trigger: 'blur' },
          { min: 1, max: 30, message: '长度在 1 到 30 个字符', trigger: 'blur' }
        ],
        annual: [
          { required: true, message: '请选择培训年度', trigger: 'blur' }
        ],
        dateStart: [
          { required: true, message: '请选择开始日期', trigger: 'blur' }
        ],
        dateEnd: [
          { required: true, message: '请选择结束日期', trigger: 'blur' }
        ],
        timeStart: [
          { required: true, message: '请选择开始时间', trigger: 'blur' }
        ],
        timeEnd: [
          { required: true, message: '请选择结束时间', trigger: 'blur' }
        ],
        location: [
          { required: true, message: '请选择培训地点', trigger: 'blur' }
        ],
        period: [
          { required: true, message: '请选择学时', trigger: 'blur' }
        ],
        phase: [
          { required: true, message: '请选择学段', trigger: 'blur' }
        ],
        subject: [
          { required: true, message: '请选择学科', trigger: 'blur' }
        ],
        member: [
          { required: true, message: '请选择培训对象', trigger: 'blur' }
        ],
        details: [
          { required: true, message: '请输入项目详情', trigger: 'blur' }
        ]
      },
      // 选项模拟数据
      options: [{
        value: '选项1',
        label: '黄金糕'
      }, {
        value: '选项2',
        label: '双皮奶'
      }, {
        value: '选项3',
        label: '蚵仔煎'
      }, {
        value: '选项4',
        label: '龙须面'
      }, {
        value: '选项5',
        label: '北京烤鸭'
      }, {
        value: '选项6',
        label: '北京烤鸭'
      }, {
        value: '选项7',
        label: '北京烤鸭'
      }, {
        value: '选项8',
        label: '北京烤鸭'
      }, {
        value: '选项9',
        label: '北京烤鸭'
      }, {
        value: '选项10',
        label: '北京烤鸭'
      }, {
        value: '选项11  ',
        label: '北京烤鸭'
      }],
      value: ''
    }
  },
  methods: {
    // 提交表单
    submitForm(formName) {
      console.log(this.form)
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style lang="scss" >
.new-project {
  // width: 1190px;
  .wrapper{
    .project-form{
      .time-wrapper,.date-wrapper{
        .el-input__inner{
          text-align: center;
        }
      }
      .quill-editor{
        padding: 0;
        top: 0px;
        position: relative;
        top: -5px;
        .ql-container{
          height: 300px;
        }
      }
      .el-input-number{
        width: 100%;
      }
      .member-choose{
        width: 100%;
        // 是否开启横向滚动条
        // .el-select__tags{
        //   >span{
        //     overflow: hidden;
        //     overflow-x: auto;
        //     display: inline-block;
        //     flex-wrap: nowrap;
        //     width:100%;
        //     white-space: nowrap;
        //   }
        // }
      }
      .period-show-wrapper{
        margin-left: 20px;
        min-width: 85px;
        font-weight: 700;
        .period-show{
        display: inline-block;
        box-sizing: border-box;
        line-height: 40px;
        height: 40px;
        width: 40px;
        border-radius: 4px;
        border: 1px solid #DCDFE6;
        background-color: #F5F7FA;
        color: #999;
        text-align: center;
        font-weight: normal;
        user-select:none;
      }
      }
    }
  }
}
</style>
